package com.kiln.juxingqs.ui

import android.content.Intent
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatDelegate
import client.global.commlib.base.FinishReciver
import client.global.commlib.utils.SharedUtil
import com.kiln.juxingqs.R
import com.kiln.juxingqs.databinding.ActivitySettingBinding
import com.kiln.juxingqs.ui.vm.SettingViewModel
import com.kiln.juxingqs.BaseMiddleActivity

//我的竞拍

class SettingActivity :
    BaseMiddleActivity<SettingViewModel, ActivitySettingBinding>() {
    override fun getLayout(): Int {
        return R.layout.activity_setting
    }

    override fun initViewModel(): SettingViewModel = createViewModel()

    override fun initView() {
        binding.event = this
        binding.vm = viewModel

        binding.darkBtn.setOnCheckedChangeListener { buttonView, isChecked ->
            SharedUtil.save("isNight",isChecked)
            AppCompatDelegate.setDefaultNightMode(if(isChecked) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO)
//            recreate()
        }
    }

    override fun initData() {

        try {
            val name = packageManager
                .getPackageInfo(packageName, 0).versionName

            binding.versionName = name
        } catch (ex: PackageManager.NameNotFoundException) {
        }

        binding.darkBtn.isChecked = SharedUtil.read("isNight",true)
    }

    fun logout() {
        SharedUtil.clear("token")
        startActivity(Intent(this@SettingActivity, LoginActivity::class.java))
        sendBroadcast(Intent(FinishReciver.FINISH_ACTION))
    }

    fun onAccountSafe() {
        startActivity(AccountSafeActivity::class.java)
    }

}